 /*
  * Mango CMS
  * Copyright 2008, Mango Web, and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
package org.mangocms.model.media;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.validator.NotNull;
import org.mangocms.model.user.User;

/**
 * Abstract base class for all media entities in the Mango media library.
 * 
 * @author <a href="tanordheim@gmail.com">Trond Arve Nordheim</a>
 * @version $Revision: 1.1 $
 */
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "mango_media_entities")
public abstract class MediaEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id @GeneratedValue
	private Integer id;
	
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "folder_id", referencedColumnName = "id")
	private MediaFolder folder;
	
	@Column(name = "spool_file")
	@NotNull
	private String spoolFile;
	
	@Column(name = "filename")
	@NotNull
	private String filename;
	
	@Column(name = "content_type")
	@NotNull
	private String contentType;
	
	@Column(name = "size")
	@NotNull
	private Long size;

	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "created_by_id", referencedColumnName = "id")
	@NotNull
	private User createdBy;

	@Column(name = "created_time")
	@NotNull
	private Date createdTime;
	
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "modified_by_id", referencedColumnName = "id")
	private User modifiedBy = null;

	@Column(name = "modified_time")
	private Date modifiedTime;

	/**
	 * Create a new MediaEntity.
	 */
	protected MediaEntity() {
		createdTime = new Date();
	}
	
	/**
	 * Create a new MediaEntity for the specified folder
	 * 
	 * @param folder
	 */
	protected MediaEntity(MediaFolder folder) {
		this();
		this.folder = folder;
	}

	/**
	 * Get the id.
	 * 
	 * @return the id.
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * Set the id.
	 * 
	 * @param id The id to set.
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * Get the folder.
	 * 
	 * @return the folder.
	 */
	public MediaFolder getFolder() {
		return folder;
	}

	/**
	 * Set the folder.
	 * 
	 * @param folder The folder to set.
	 */
	public void setFolder(MediaFolder folder) {
		this.folder = folder;
	}

	/**
	 * Get the spoolFile.
	 * 
	 * @return the spoolFile.
	 */
	public String getSpoolFile() {
		return spoolFile;
	}

	/**
	 * Set the spoolFile.
	 * 
	 * @param spoolFile The spoolFile to set.
	 */
	public void setSpoolFile(String spoolFile) {
		this.spoolFile = spoolFile;
	}

	/**
	 * Get the filename.
	 * 
	 * @return the filename.
	 */
	public String getFilename() {
		return filename;
	}

	/**
	 * Set the filename.
	 * 
	 * @param filename The filename to set.
	 */
	public void setFilename(String filename) {
		this.filename = filename;
	}

	/**
	 * Get the contentType.
	 * 
	 * @return the contentType.
	 */
	public String getContentType() {
		return contentType;
	}

	/**
	 * Set the contentType.
	 * 
	 * @param contentType The contentType to set.
	 */
	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	/**
	 * Get the size.
	 * 
	 * @return the size.
	 */
	public Long getSize() {
		return size;
	}

	/**
	 * Set the size.
	 * 
	 * @param size The size to set.
	 */
	public void setSize(Long size) {
		this.size = size;
	}

	/**
	 * Get the createdBy.
	 * 
	 * @return the createdBy.
	 */
	public User getCreatedBy() {
		return createdBy;
	}

	/**
	 * Set the createdBy.
	 * 
	 * @param createdBy The createdBy to set.
	 */
	public void setCreatedBy(User createdBy) {
		this.createdBy = createdBy;
	}

	/**
	 * Get the createdTime.
	 * 
	 * @return the createdTime.
	 */
	public Date getCreatedTime() {
		return createdTime;
	}

	/**
	 * Set the createdTime.
	 * 
	 * @param createdTime The createdTime to set.
	 */
	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	/**
	 * Get the modifiedBy.
	 * 
	 * @return the modifiedBy.
	 */
	public User getModifiedBy() {
		return modifiedBy;
	}

	/**
	 * Set the modifiedBy.
	 * 
	 * @param modifiedBy The modifiedBy to set.
	 */
	public void setModifiedBy(User modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	/**
	 * Get the modifiedTime.
	 * 
	 * @return the modifiedTime.
	 */
	public Date getModifiedTime() {
		return modifiedTime;
	}

	/**
	 * Set the modifiedTime.
	 * 
	 * @param modifiedTime The modifiedTime to set.
	 */
	public void setModifiedTime(Date modifiedTime) {
		this.modifiedTime = modifiedTime;
	}

}
